﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Circa.Protocol.Irc {
    public class ConnectionFactory {
        private ConnectionFactory( ) { }

        public static Connection Create( Server server, bool useSsl ) {
            if ( useSsl ) {
                throw new NotImplementedException( "SSL not supported yet" );

                //if ( ( server.UseHttpsProxy ?? server.Network.UseHttpsProxy ) ?? false ) {
                //    string proxyHostName = server.HttpsProxyHostName ?? server.Network.HttpsProxyHostName;
                //    if ( string.IsNullOrEmpty( proxyHostName ) ) {
                //        throw new InvalidOperationException( "UseHttpsProxy is true, but HttpsProxyHostName is null or empty" );
                //    }
                //
                //    int proxyPort = server.HttpsProxyPort ?? server.Network.HttpsProxyPort ?? 0;
                //    if ( proxyPort < 1 || proxyPort > 65535 ) {
                //        throw new InvalidOperationException( "UseHttpsProxy is true, but HttpsProxyPort is invalid" );
                //    }
                //
                //    throw new NotImplementedException( "SSL not supported yet" );
                //    //return new HttpsProxyConnection( server.HostNames.First( ), server.Ports.First( ), proxyHostName, proxyPort );
                //} else {
                //    throw new NotImplementedException( "SSL not supported yet" );
                //    //return new SslConnection( server.HostNames.First( ), server.Ports.First( ) );
                //}
            } else {
                return new Connection( server.HostNames.First( ), server.Ports.First( ) );

                //if ( ( server.UseHttpProxy ?? server.Network.UseHttpProxy ) ?? false ) {
                //    string proxyHostName = server.HttpProxyHostName ?? server.Network.HttpProxyHostName;
                //    if ( string.IsNullOrEmpty( proxyHostName ) ) {
                //        throw new InvalidOperationException( "UseHttpProxy is true, but HttpProxyHostName is null or empty" );
                //    }
                //
                //    int proxyPort = server.HttpProxyPort ?? server.Network.HttpProxyPort ?? 0;
                //    if ( proxyPort < 1 || proxyPort > 65535 ) {
                //        throw new InvalidOperationException( "UseHttpProxy is true, but HttpProxyPort is invalid" );
                //    }
                //
                //    return new HttpProxyConnection( server.HostNames.First( ), server.Ports.First( ), proxyHostName, proxyPort );
                //} else {
                //    return new Connection( server.HostNames.First( ), server.Ports.First( ) );
                //}
            }
        }

    }

}
